package com.heima.comment.controller;

import com.heima.comment.dto.CommentDto;
import com.heima.comment.dto.CommentLikeDto;
import com.heima.comment.dto.CommentSaveDto;
import com.heima.comment.service.ICommentService;
import com.heima.common.dto.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/comment")
@Api(tags = "发表评论API") // Swagger,knife4j
public class CommentController {

    @Autowired
    private ICommentService commentService;

    /**
     * 发表评论-保存
     * @param dto
     * @return
     */
    @PostMapping("/save")
    @ApiOperation(value = "发表评论-保存", notes = "author:liJie")  // value指名称  notes 备注
    @ApiImplicitParam(name = "dto", value = "接收参数", required = true, dataType = "CommentSaveDto")
    public ResponseResult saveComment(@RequestBody CommentSaveDto dto) {
        return commentService.saveComment(dto);
    }

    /**
     * 评论列表展示
     * @param dto
     * @return
     */
    @PostMapping("/load")
    @ApiOperation(value = "发表评论-列表展示", notes = "author:liJie")  // value指名称  notes 备注
    @ApiImplicitParam(name = "dto", value = "接收参数", required = true, dataType = "CommentDto")
    public ResponseResult load(@RequestBody CommentDto dto) {
        return commentService.load(dto);
    }

    /**
     * 评论点赞
     * @param dto
     * @return
     */
    @PostMapping("/like")
    @ApiOperation(value = "发表评论-点赞", notes = "author:liJie")  // value指名称  notes 备注
    @ApiImplicitParam(name = "dto", value = "接收参数", required = true, dataType = "CommentLikeDto")
    public ResponseResult like(@RequestBody CommentLikeDto dto){
        return commentService.like(dto);
    }
}
